package core.loaders.io;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 * @author Norvin Altamirano Ruiz the file reader.
 */
public class GameFileReader {

	private BufferedReader buffer;

	private String fileName;

	public GameFileReader(String filename) {
		this.fileName = filename;
		if (null == fileName) {
			throw new IllegalArgumentException(
					" Reader for null can't be created");
		}
	}

	public boolean openFile() {
		boolean correct = false;
		try {
			System.out.println(".........." + fileName);
			

			FileReader fr = new FileReader(getClass().getResource(fileName).getPath().toString());

			buffer = new BufferedReader(fr);
			
			//System.in.read();
			correct = true;
		} catch (Exception x) {
			correct = false;
			
			x.printStackTrace();
		}
		return correct;
	}

	public void closeFile() {
		try {
			buffer.close();

		} catch (Exception x) {

			x.printStackTrace();
		}
	}

	public String readLine() {
		String line = new String();
		try {
			line = buffer.readLine();
		} catch (Exception x) {

			//x.printStackTrace();
		}
		return line;
	}

	public int readCharacter() {
		int car = -1;
		try {
			car = buffer.read();
		} catch (Exception x) {

			x.printStackTrace();
		}
		return car;
	}

	public String getName() {
		return fileName;
	}
}
